package com.juno.cafenoa.util;

import android.content.Context;
import android.os.PowerManager;
import android.telephony.TelephonyManager;
import android.util.Log;

/**
 * 필요한 util 정의한 class.
 * @author JUNHO
 */
public class Util {
    private static PowerManager.WakeLock sCpuWakeLock;
    
	/**
	 * url 세팅함
	 * @param page 프로토콜정의서에 정의된 PAGE 이름.
	 * @return URL 리턴.
	 */
	public static String getUrl(String page){
		String url;
		//TEST URL
//		url = "http://tpiece.dyndns.org:8080/CafeNoa/" + page+".jsp?";;
		//상용 URL
		url = "http://rouge3351.cafe24.com/" + page+".jsp?";
		return url;
	}
	
	/**
	 * 핸드폰의 전화번호를 읽어옴.
	 * @param context
	 * @return
	 */
	public static String getPhoneNum(Context context){
		TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		String phoneNum = telManager.getLine1Number();
		return phoneNum;
		
	}
    /**
     * CPU가 Sleep모드로 들어갈시 다시 되살림.
     * @param context
     */
    public static void acquireCpuWakeLock(Context context) {
    	Log.i("Util","Acquire cpu wake lock");
    	if (sCpuWakeLock != null) {
    		return;
    	}
    	PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    	sCpuWakeLock = pm.newWakeLock( PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | 
    			PowerManager.ON_AFTER_RELEASE, "Util");
            sCpuWakeLock.acquire();
    }
    
    public static void releaseCpuLock() {
    	Log.i("Util","Releasing cpu wake lock");
    	if (sCpuWakeLock != null) {
    		sCpuWakeLock.release();
    		sCpuWakeLock = null;
    	}
    }
}
